package com.quark.cloud.web.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.quark.cloud.web.service.SekillService;
import com.quark.cloud.web.vo.Sekill;
import com.quark.cloud.web.vo.dto.ResultEntity;

@RestController
public class SekillController {
    private Logger log = LoggerFactory.getLogger(SekillController.class);
	@Autowired
	private SekillService sekillService;
	
	@RequestMapping(value="/sekills")
	public ResponseEntity<List<Sekill>> readUserInfo(){
		List<Sekill> sekills=sekillService.searchAll();		
		return new ResponseEntity<List<Sekill>>(sekills,HttpStatus.OK);
	}
	
	@RequestMapping(value="/sekills/html",method =RequestMethod.GET)
	public String queryAllSekills(Model model){
		List<Sekill> sekills=sekillService.searchAll();
		model.addAttribute("sekills", sekills);
		return "index";
	}
	
	@RequestMapping(value="sekill/save",method=RequestMethod.POST,
			produces = {"application/json;charset=utf-8"})
	@ResponseBody
	public ResultEntity<Sekill> saveSekill(@RequestBody Sekill sekill){
		log.debug(sekill.toString());
		sekill.setId(1);
		sekill.setName("秒杀Iphone");
		sekill.setDescription("1000元秒杀商品");
		sekill.setNumber(100);
		return new ResultEntity<Sekill>(true, sekill);
	}
}
